<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>思维导图</title>

	<link href="favicon.ico" type="image/x-icon" rel="shortcut icon">

	<!-- bower:css -->
	<link rel="stylesheet" href="./bower_components/bootstrap/dist/css/bootstrap.css" />
	<link rel="stylesheet" href="./bower_components/codemirror/lib/codemirror.css" />
	<link rel="stylesheet" href="./bower_components/hotbox/hotbox.css" />
	<link rel="stylesheet" href="./bower_components/kityminder-core/dist/kityminder.core.css" />
	<link rel="stylesheet" href="./bower_components/color-picker/dist/color-picker.min.css" />
	<!-- endbower -->
	<link rel="stylesheet" href="kityminder.editor.min.css">

	<style>		
		html, body {
			margin: 0;
			padding: 0;
			height: 100%;
			overflow: hidden;
		}
		h1.editor-title {
			background: #393F4F;
			color: white;
			margin: 0;
			height: 40px;
			font-size: 14px;
			line-height: 40px;
			font-family: 'Hiragino Sans GB', 'Arial', 'Microsoft Yahei';
			font-weight: normal;
			padding: 0 20px;
		}
		div.minder-editor-container {
			position: absolute;
			top: 0px;
			bottom: 0;
			left: 0;
			right: 0;
		}
		.append-group{
			300px
		}
        .btn-baocun{
			position: absolute;
		    z-index: 99999;
		    bottom: 40px;
		    right: 40px;
		    font-size: 14px;
		    background: #0066CC;
		    width: 120px;
		    line-height: 40px;
		    border: none;
		    color: #fff;
        }	
        .append-group{
        	width: 300px;
        }	
        .arrange-group, .operation-group{
        	width: 100px;
        }
	</style>
</head>
<body ng-app="kityminderDemo" id="ngSection" ng-controller="MainController">
<kityminder-editor on-init="initEditor(editor, minder)"   data-theme="fresh-green"></kityminder-editor>
</body>

<!-- bower:js -->
<script src="./bower_components/jquery/dist/jquery.js"></script>
<script src="./bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="./bower_components/angular/angular.js"></script>
<script src="./bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script src="./bower_components/codemirror/lib/codemirror.js"></script>
<script src="./bower_components/codemirror/mode/xml/xml.js"></script>
<script src="./bower_components/codemirror/mode/javascript/javascript.js"></script>
<script src="./bower_components/codemirror/mode/css/css.js"></script>
<script src="./bower_components/codemirror/mode/htmlmixed/htmlmixed.js"></script>
<script src="./bower_components/codemirror/mode/markdown/markdown.js"></script>
<script src="./bower_components/codemirror/addon/mode/overlay.js"></script>
<script src="./bower_components/codemirror/mode/gfm/gfm.js"></script>
<script src="./bower_components/angular-ui-codemirror/ui-codemirror.js"></script>
<script src="./bower_components/marked/lib/marked.js"></script>
<script src="./bower_components/kity/dist/kity.min.js"></script>
<script src="./bower_components/hotbox/hotbox.js"></script>
<script src="./bower_components/json-diff/json-diff.js"></script>
<script src="./bower_components/kityminder-core/dist/kityminder.core.min.js"></script>
<script src="./bower_components/color-picker/dist/color-picker.min.js"></script>
<!-- endbower -->

<script src="kityminder.editor.min.js"></script>
<script src="all.js" type="text/javascript" charset="utf-8"></script>

<script>
	var model=angular.module('kityminderDemo', ['kityminderEditor'])
	model.controller('MainController', function($scope) {
		$scope.type=ComFunJS.getQueryString('type');
		$scope.use=ComFunJS.getQueryString('use');
		$scope.teamId=ComFunJS.getQueryString('teamId');
		$scope.data="";
		$scope.Drawnaotu="";
		$scope.initEditor = function(editor, minder) {
			window.editor = editor;
			window.minder = minder;
			editor.minder.importJson($scope.data)
			$('#kity_svg_6').click(function(){
				$scope.data=editor.minder.exportJson() 
				$scope.post()
			})			
		};
        $scope.initWebSocket=function(teamId){ //初始化weosocket
            //ws地址
            const wsuri ="ws://www.zcxy360.com/sandtable/webSocketServer/"+$scope.teamId;
            $scope.websock = new WebSocket(wsuri);
            $scope.websock.onmessage = $scope.websocketonmessage;
        };
        $scope.websocketonmessage=function(e){ //数据接收
        	var _this=this;
        	console.log(e)
        	if(e!=undefined){
            	var redata =JSON.parse(e.data);    	
				if(JSON.stringify($scope.data)!=redata.teamdraw.content){
					$scope.data=JSON.parse(redata.teamdraw.content);
					editor.minder.importJson($scope.data)	
				}
        	}
        };
        $scope.websocketclose=function(e){  //关闭
            console.log("connection closed (" + e.code + ")");
        };			
		$scope.getsession=function(){
			$scope.Drawnaotu=localStorage.getItem('Drawnaotu');
				setTimeout(function(){
				if($scope.data==''&&$scope.Drawnaotu!=''){
					$scope.data=JSON.parse($scope.Drawnaotu)
					editor.minder.importJson($scope.data)					
				}
				if(JSON.stringify($scope.data)==$scope.Drawnaotu){			
					return
				}else{
					if($scope.Drawnaotu!=''){
						$scope.data=JSON.parse($scope.Drawnaotu)
					}
					
					editor.minder.importJson($scope.data)					
				}				
			},200)
		};		
		$scope.post=function(type){
			localStorage.setItem('Drawnaotu',JSON.stringify($scope.data))			
		};		
	});
	$(document).ready(function(){
		var scope = angular.element(ngSection).scope()
		scope.getsession();
		if(!scope.use){
			scope.initWebSocket()
		}
	})
</script>
</html>
